  //
//  HRGetUserinfoViewModel.m
//  Hear
//
//  Created by mac on 2017/4/13.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRGetUserinfoViewModel.h"
#import "HRUpdataUserInfoModel.h"
#import "HRCoverTimeModel.h"
@implementation HRGetUserinfoViewModel

- (void)getUserInfoRequestModel:(NSDictionary *)requstDict isSeccess:(void(^)(HRUpdataUserInfoModel *infModel))isSeccess {
    YTKApi *api = [YTKApi apiGetWithUrl:@"UserInfo/Get_GetUserInfoByLocalId" para:requstDict];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            
            NSDictionary *dict = request.responseJSONObject;
            
            if ([requstDict[@"CurrentUserLocalId"] isEqualToString:USERID]){
                [[NSUserDefaults standardUserDefaults] setObject:dict[@"BodyContent"] forKey:@"userInfo"];
            }
            
            isSeccess( [HRUpdataUserInfoModel modelWithJSON:dict[@"BodyContent"]]);
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        }];
    }];
}

#pragma mark 获取用户关系(好友/非好友)
- (void)getUserFollowInfo:(NSDictionary *)requstDict andTimeCount:(void(^)(NSInteger timeCount))timeCount {
    YTKApi *api = [YTKApi apiGetWithUrl:@"UserInfo/Get_GetUserFollowInfo" para:requstDict];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            
            NSDictionary *dict = request.responseJSONObject;
            NSDictionary *pata = [dict[@"BodyContent"] jsonValueDecoded];
            if ([dict[@"CodeStatus"] intValue] == 20000 && ![dict[@"Message"] isEqualToString:@"暂无数据"]){
                timeCount([HRCoverTimeModel calcDaysFromBegin:pata[@"CreateTime"] end:[NSDate date]]);
            }else{
                timeCount(100000);

            }
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
//            isSeccess(NO);
        }];
    }];
}

#pragma mark 获取用户关系(关注/非关注)
- (void)judgeUserFollowInfo:(NSDictionary *)requstDict andTimeCount:(void(^)(NSInteger timeCount))timeCount {
    YTKApi *api = [YTKApi apiGetWithUrl:@"UserInfo/Get_GetUserFollowInfo_" para:requstDict];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            
            NSDictionary *dict = request.responseJSONObject;
            NSDictionary *pata = [dict[@"BodyContent"] jsonValueDecoded];
            if ([dict[@"CodeStatus"] intValue] == 20000 && ![dict[@"Message"] isEqualToString:@"暂无数据"]){
                timeCount([HRCoverTimeModel calcDaysFromBegin:pata[@"CreateTime"] end:[NSDate date]]);
            }else{
                timeCount(100000);
            }
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
//            isSeccess(NO);
        }];
    }];
}

@end
